<!DOCTYPE html>
<html>
<head>
<title>编辑内容</title>
[#include "/WEB-INF/admin/include/common.html"]
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>编辑内容</h5>
            </div>
           <form id="inputForm" action="update" method="post">
           		<input type="hidden" name="id" value="${content.id}" />
           		<input type="hidden" name="categoryId" value="${content.category.id}" />
	            <div class="ibox-content">
	                <div class="form-horizontal clearfix">
	                	<div class="form-group">
	                        <label class="col-sm-3 control-label">分类：</label>
	                        <div class="col-sm-3">
	                            ${content.category.name}
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">标题：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="标题" class="form-control" type="text" name="title" value="${content.title}">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">图片：</label>
	                        <div class="col-sm-3">
	                            <input type="text" name="image" class="form-control" value="${content.image}"/>
	                        </div>
	                        <div class="col-sm-3">
								<a href="javascript:;" id="filePicker" class="btn btn-primary">选择文件</a>
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">设置：</label>
	                        <div class="col-sm-3">
	                            <div class="checkbox">
	                               <label class="m-r"><input type="checkbox" name="isEnabled" value="true" [#if content.isEnabled]checked[/#if]/>启用</label>
	                            </div>
	                        </div>
	                    </div>
	                    <div class="form-group">
                            <label class="col-sm-3 control-label">标签：</label>
                            <div class="col-sm-3">
                                <input type="text" id="tag" class="form-control" />
                            </div>
                            <div class="col-sm-3">
                                <a href="javascript:;" id="addTag" class="btn btn-primary">添加</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">&nbsp;</label>
                            <div class="col-sm-3">
                                <ul class="tag-list" id="tagList" style="padding: 0">
                                    [#list content.tags as tag]
                                    <li><a href="javascript:;">${tag}&nbsp;x</a><input type="hidden" name="tags" value="${tag}"></li>
                                    [/#list]
                                </ul>
                            </div>
                        </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">关键词：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="关键词" class="form-control" type="text" name="keywords" value="${content.keywords}">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">描述：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="描述" class="form-control" type="text" name="description" value="${content.description}">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">简介：</label>
	                        <div class="col-sm-8">
	                           <textarea id="introduction" name="introduction" class="ibox-content no-padding" style="height: 250px;">${content.introduction?html}</textarea>
	                        </div>
	                    </div>
	                    [#list contentFields as contentField]
							[#if contentField.type=="input" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-3">
										<input type="text" name="${contentField.name}" value="${content.getAttribute(contentField.name)}" title="${contentField.prompt}"  class="form-control" maxlength="200" />
									</div>
								</div>
							[#elseif contentField.type=="textarea" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-8">
										<textarea name="${contentField.name}" class="form-control" style="height: 250px;" title="${contentField.prompt}">${content.getAttribute(contentField.name)}</textarea>
									</div>
								</div>
							[#elseif contentField.type=="editor" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-8">
										<textarea name="${contentField.name}" class="ibox-content no-padding fieldEditor" style="height: 250px;" title="${contentField.prompt}">${content.getAttribute(contentField.name)}</textarea>
									</div>
								</div>
							[#elseif contentField.type=="radio" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-3">
	                            		<div class="radio">
											[#list contentField.fieldAttribute.radioAttributes as radioAttribute] 
												<label class="m-r"><input name="${contentField.name}" value="${radioAttribute[1]}" type="radio" [#if content.getAttribute(contentField.name)==radioAttribute[1]]checked[/#if]>${radioAttribute[0]}</label>
											[/#list]
										</div>
									</div>
								</div>
							[#elseif contentField.type=="checkbox" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-3">
										<div class="checkbox">
											[#list contentField.fieldAttribute.checkboxAttributes as checkboxAttribute] 
												<label class="m-r"><input name="${contentField.name}" value="${radioAttribute[1]}" type="checkbox" [#if content.getAttribute(contentField.name)==radioAttribute[1]]checked[/#if]>${radioAttribute[0]}</label>
											[/#list]
										</div>
									</div>
								</div>
							[#elseif contentField.type=="select" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-3">
										<select class="form-control" name="${contentField.name}">
											[#list contentField.fieldAttribute.selectAttributes as selectAttribute] 
												<option value="${selectAttribute[1]}" [#if content.getAttribute(contentField.name)==selectAttribute[1]]checked[/#if]>${selectAttribute[0]}</option>
											[/#list]
										</select>
									</div>
								</div>
							[#elseif contentField.type=="date" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-3">
										<input type="text" name="${contentField.name}" value="${content.getAttribute(contentField.name)}" class="form-control Wdate" onfocus="WdatePicker({dateFmt: '${contentField.fieldAttribute.format}'});" />
									</div>
								</div>
							[#elseif contentField.type=="file" && contentField.isEnabled]
								<div class="form-group">
									<label class="col-sm-3 control-label">${contentField.alias}：</label>
									<div class="col-sm-3">
										<input type="text" name="${contentField.name}" value="${content.getAttribute(contentField.name)}" class="form-control" title="${contentField.prompt}" />
									</div>
									<div class="col-sm-3">
										<a href="javascript:;" class="btn btn-primary fieldFilePicker">选择文件</a>
									</div>
								</div>
							[/#if]
						[/#list]
	                </div>
	            </div>
	            <div class="modal-footer col-sm-3 col-sm-offset-2">
	                <button type="submit" class="btn btn-w-m btn-primary">确定</button>
	                <button type="button" class="btn btn-w-m btn-default" onclick="history.back(); return false;">取消</button>
	            </div>
            </form>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
$().ready(function() {

	var $inputForm = $("#inputForm");
	var $introduction = $("#introduction");
	var $filePicker = $("#filePicker");
	var $addTag = $("#addTag");
    var $tag = $("#tag");
    var $tagList = $("#tagList");
	
	$filePicker.uploader();
	$introduction.editor();
	
	$.each($(".fieldEditor"),function(index,item){
		$(item).editor();
	});
	
	$.each($(".fieldFilePicker"),function(index,item){
		$(item).uploader();
	});
	
	$addTag.on("click",function(){
        var tag = $tag.val();
        if(tag==""){
            alert("请输入标签!");
            return;
        }
        $tagList.append('<li><a href="javascript:;">'+tag+'&nbsp;x</a><input type="hidden" name="tags" value="'+tag+'"></li>');
        $tag.val("");
    });
    
    $tagList.on("click","a",function(){
         $(this).parent().remove();
    });
	
	// 表单验证
	$inputForm.validate({
		rules: {
			title: "required",
			categoryId: "required",
			isEnabled: "required"
			[#list contentFields as contentField]
				[#if contentField.isEnabled]
					,${contentField.name}: {
						[#if contentField.isRequired && contentField.pattern??]
							required: true,
							pattern: ${contentField.pattern}
						[#elseif contentField.isRequired]
							required: true
						[#elseif contentField.pattern]
							pattern: ${contentField.pattern}
						[/#if]
					}
				[/#if]
			 [/#list]
		},
		messages: {
			[#assign contentFieldIndex=0]
			[#list contentFields as contentField]
				[#if contentField.isEnabled && contentField.pattern??]
					[#if contentFieldIndex>0],[/#if]${contentField.name}: {
						pattern: "${contentField.alias}错误"
					}
					[#assign contentFieldIndex=contentFieldIndex+1]
				[/#if]
			 [/#list]
		}
	});

});
</script>
